package VectorApproach;

import java.util.ArrayList;
import XmlLoader.Position;

public class Grid {
	
	public Position pos = null;
	ArrayList<TrajVector> listTraj = null;
	ArrayList<Integer> listClusterCount = null;
	
	protected int cubeLen = 0;
	
	public Grid(Position pos, int cubeLen, int totalClusterNum) {
		this.pos = pos;
		this.cubeLen = cubeLen;
		this.listTraj = new ArrayList<TrajVector>();
		this.listClusterCount = new ArrayList<Integer>();
		int index = 0;
		while(index < totalClusterNum) {
			this.listClusterCount.add(0);
			index = index + 1;
		}
	}
	
	public void ACT001_addNewTraj(TrajVector traj, int clusterID) {
		int indexQ = 0;
		boolean isInsert = false;
		
		while(!isInsert && indexQ < this.listTraj.size()) {
			if(traj.GET001_trajID() < this.listTraj.get(indexQ).GET001_trajID()) {
				this.listTraj.add(traj);
				isInsert = true;
			}
			indexQ = indexQ + 1;
		}
		
		if(!isInsert) {
			this.listTraj.add(traj);
		}
		
		this.listClusterCount.set(clusterID, this.listClusterCount.get(clusterID) + 1);
	}
	
	public int GET001_maxClusterID() {
		int maxNum = 0, maxID = 0;
		int index = 0;
		while(index < this.listClusterCount.size()) {
			if(this.listClusterCount.get(index) > maxNum) {
				maxNum = this.listClusterCount.get(index);
				maxID = index;
			}
			index = index + 1;
		}
		if(maxNum == 0) {
			maxID = -1;
		}
		return maxID;
	}
}
